;(function() {
		init_parsley();
		$.fn.modal.Constructor.prototype.enforceFocus = function () { };
	    $('.select2-single').select2();
		$('.datepicker').datepicker({format: 'yyyy-mm-dd',todayHighlight:true,clearBtn:true,autoclose:true , language:"zh-CN"});
		
		//清空
		$("#form-empty").click(function(){
			$("#validate-form")[0].reset();
		});
		//提交并且购卡
		$("#form-buy").click(function(){
	   		var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
	   			loading();
	   			$.post(
	   				"/gym/GymMember/member_in_post",
	   				$("#validate-form").serialize(),
	   				function(data){
	   					close_loading();
			      		if(data.flag){
			      			$("#myModal").modal("hide");
			      			toastr['success']("入会成功！", ''); 
			      			setTimeout(function(){
			      				$("#myModalBody").load("/gym/GymMember/buy_card",{"id":data.data},function(){
                                    $("#myModalTitle").text("购卡");
		  	   	      				$("#myModal").modal("show");
		  	  					});
			      			},800);
			      		}else{
			      		 	toastr['error'](data.msg,"操作失败！"); 
			      		}
	   				}
	   			);
	   		}
		});
	   	$("#form-submit").click(function(){
	   		var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
	   			loading();
	   			$.post(
	   				"/gym/GymMember/member_in_post",
	   				$("#validate-form").serialize(),
	   				function(data){
	   					close_loading();
			      		if(data.flag){
                            $("#myModal").modal("hide");
			      			toastr['success']("入会成功！", ''); 
			      			$("#form-empty").trigger("click");
			      		}else{
			      		 	toastr['error'](data.msg,"操作失败！"); 
			      		}
	   				}
	   			);
	   		}
	   	})
	   	
})();